﻿
//***********************************************************************
// * Module:   MsjHzSldedsfzHandler
// * 作者:  Dzs
// * Modified: 2013-05-29
// * Purpose: Definition of the Class MsjHzSldedsfzHandler 业务逻辑处理Handler类
// ***********************************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;
using System.Data;
using XWG.Framework.Query;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using XWG.Framework.MSException;
using XWG.Framework.AuthUtility;
using XWG.Framework.AuthEntity;
using XWG.Framework.AuthSPConst;
using XWG.Framework.AuthBLL;
using XWG.JWBST.JWBSTEntity;
using XWG.JWBST.JWBSTSPConst;
using XWG.JWBST.JWBSTBLL;
using JWBSTAPP.CommonClass;

namespace JWBSTAPP.AjaxServer
{
    /// <summary>
    /// MsjHzSldedsfzHandler 的摘要说明
    /// </summary>
    public class MsjHzSldedsfzHandler : JWBSTAPP.CommonClass.HttpHandlerBase, System.Web.SessionState.IRequiresSessionState
    {
      
        #region 添加记录
      /// <summary>
      /// 添加记录
      /// </summary>
      protected void AddRecord()
        {
             HttpContext context = HttpContext.Current;
            context.Response.ContentType = "text/plain";
            ResultModel mResultModel = new ResultModel(); //初始化返回类型
            try
            {           
            MsjHzSldedsfz mMsjHzSldedsfz = new MsjHzSldedsfz();
            mMsjHzSldedsfz.Slid = Guid.NewGuid().ToString(); //主键
                 mMsjHzSldedsfz.Czdsspcs = context.Request.Form["texCzdsspcs"]; //常住地所属派出所(字典)
                 mMsjHzSldedsfz.Xm = context.Request.Form["texXm"]; //姓名
                 mMsjHzSldedsfz.Xb = context.Request.Form["texXb"]; //性别(字典)
                 mMsjHzSldedsfz.Mz = context.Request.Form["texMz"]; //民族(字典)
                 mMsjHzSldedsfz.Sfzh = context.Request.Form["texSfzh"]; //身份证号码
                 mMsjHzSldedsfz.Csrq = context.Request.Form["texCsrq"]; //出生日期
                 mMsjHzSldedsfz.Slrgddh = context.Request.Form["texSlrgddh"]; //申领人固定电话
                 mMsjHzSldedsfz.Czhkdjdz = context.Request.Form["texCzhkdjdz"]; //常住户口登记地址
                 mMsjHzSldedsfz.Ywlb = context.Request.Form["texYwlb"]; //业务类别(数据字典)
                 mMsjHzSldedsfz.Sjjzdz = context.Request.Form["texSjjzdz"]; //实际居住地址
                 mMsjHzSldedsfz.Szdsspcs = context.Request.Form["texSzdsspcs"]; //实住地所属派出所(字典)
                 mMsjHzSldedsfz.Slyy = context.Request.Form["texSlyy"]; //申领原因(1第一次申领 2丢失补领)
                 mMsjHzSldedsfz.Dw = context.Request.Form["texDw"]; //单位
                 if (!string.IsNullOrEmpty(context.Request.Form["H_File"]))
                 {
                     mMsjHzSldedsfz.Zp = new ImageToByte().ToByte("/uploadfiles/" + context.Request.Form["H_File"]); ; //二代身份证照片    
                 }
                 
                 mMsjHzSldedsfz.Zjydszsheng = context.Request.Form["texZjydszsheng"]; //证件邮递所在省(字典)
                 mMsjHzSldedsfz.Zjydszshi = context.Request.Form["texZjydszshi"]; //证件邮递所在市(字典)
                 mMsjHzSldedsfz.Zjydxxdz = context.Request.Form["texZjydxxdz"]; //证件邮递详细地址
                 mMsjHzSldedsfz.Yb = context.Request.Form["texYb"]; //邮编
                 mMsjHzSldedsfz.Jtcyyxm = context.Request.Form["texJtcyyxm"]; //家庭成员一姓名
                 mMsjHzSldedsfz.Jtcyyyhzgx = context.Request.Form["texJtcyyyhzgx"]; //家庭成员一与户主关系(字典)
                 mMsjHzSldedsfz.Jtcyysfzh = context.Request.Form["texJtcyysfzh"]; //家庭成员一身份证号
                 mMsjHzSldedsfz.Jtcyyczhkdjdz = context.Request.Form["texJtcyyczhkdjdz"]; //家庭成员一常住户口登记地址
                 mMsjHzSldedsfz.Jtcyexm = context.Request.Form["texJtcyexm"]; //家庭成员二姓名
                 mMsjHzSldedsfz.Jtcyeyhzgx = context.Request.Form["texJtcyeyhzgx"]; //家庭成员二与户主关系(字典)
                 mMsjHzSldedsfz.Jtcyesfzh = context.Request.Form["texJtcyesfzh"]; //家庭成员二身份证号
                 mMsjHzSldedsfz.Jtcyeczhkdjdz = context.Request.Form["texJtcyeczhkdjdz"]; //家庭成员二常住户口登记地址
                 mMsjHzSldedsfz.Jtcysxm = context.Request.Form["texJtcysxm"]; //家庭成员三姓名
                 mMsjHzSldedsfz.Jtcysyhzgx = context.Request.Form["texJtcysyhzgx"]; //家庭成员三与户主关系(字典)
                 mMsjHzSldedsfz.Jtcyssfzh = context.Request.Form["texJtcyssfzh"]; //家庭成员三身份证号
                 mMsjHzSldedsfz.Jtcysczhkdjdz = context.Request.Form["texJtcysczhkdjdz"]; //家庭成员三常住户口登记地址
                 mMsjHzSldedsfz.Dbrxm = context.Request.Form["texDbrxm"]; //担保人姓名
                 mMsjHzSldedsfz.Dbrxb = context.Request.Form["texDbrxb"]; //担保人性别(字典)
                 mMsjHzSldedsfz.Dbrmz = context.Request.Form["texDbrmz"]; //担保人民族(字典)
                 mMsjHzSldedsfz.Dbrsfzh = context.Request.Form["texDbrsfzh"]; //担保人身份证号
                 mMsjHzSldedsfz.Dbrlxsj = context.Request.Form["texDbrlxsj"]; //担保人联系手机
                 mMsjHzSldedsfz.Dbrdz = context.Request.Form["texDbrdz"]; //担保人地址
                 mMsjHzSldedsfz.Yzm = context.Request.Form["texYzm"]; //验证码

                 mMsjHzSldedsfz.Cjsj = context.Request.Form["texCjsj"]; //创建时间(2013-05-28 09:13:01)
                 mMsjHzSldedsfz.Cjr = context.Request.Form["texCjr"]; //创建人(人员ID)
                 mMsjHzSldedsfz.Cjrdw = context.Request.Form["texCjrdw"]; //创建单位(单位ID)
                 mMsjHzSldedsfz.Xgr = context.Request.Form["texXgr"]; //修改人(人员ID)
                 mMsjHzSldedsfz.Xgrdw = context.Request.Form["texXgrdw"]; //修改人单位(单位ID)
                 mMsjHzSldedsfz.Xgsj = context.Request.Form["texXgsj"]; //修改时间(2013-05-28 09:13:01)
                 mMsjHzSldedsfz.Enabled = Enabled.TRUE; //是否有效（1有效，0无效）
                 mMsjHzSldedsfz.Movesign = context.Request.Form["texMovesign"]; //是否传输（1已，0未）
            
            mResultModel = MsjHzSldedsfzBLL.Insert(mMsjHzSldedsfz,context.Session["UserID"], true); //新建操作
            context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回
            }
            catch (Exception ex)
            {
                MSEx.DealErr(ex, string.Empty);
                mResultModel.ErrorCode = -9999;
                mResultModel.ISSucceed = false;
                context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回
            }
        }
        #endregion
        
        #region 删除记录
      /// <summary>
      /// 删除记录
      /// </summary>
       protected void DeleteRecord()
        {
            HttpContext context = HttpContext.Current;
            context.Response.ContentType = "text/plain";
            ResultModel mResultModel = new ResultModel(); //声明返回类型
            string paramKey = context.Request.Params["id"];
            try
            {
              if (string.IsNullOrEmpty(paramKey))
                {
                    mResultModel.ErrorCode = -9991;
                    mResultModel.ISSucceed = false;
                    context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回    
                    return ;
                }
                
                MsjHzSldedsfz mMsjHzSldedsfz = new MsjHzSldedsfz(); 
                if (!string.IsNullOrEmpty(paramKey))
                {
                    mResultModel = MsjHzSldedsfzBLL.Delete(paramKey, context.Session["UserID"], true); //删除对应的信息
                    context.Response.Write(JsonConvert.SerializeObject(mResultModel));  //序列化后返回
                }
            }
            catch (Exception ex)
            {
                MSEx.DealErr(ex, string.Empty); //写入异常日志
                mResultModel.ErrorCode = -9999; //-9999代码是系统异常通用代码
                mResultModel.ISSucceed = false; //行为执行失败
                context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回
            }            
        } 
        #endregion
     
        #region 修改记录
      /// <summary>
      /// 修改记录
      /// </summary>
      protected void EditRecord()
        {
            HttpContext context = HttpContext.Current;
            context.Response.ContentType = "text/plain";
            ResultModel mResultModel = new ResultModel(); //初始化返回类型
           MsjHzSldedsfz mMsjHzSldedsfz = new MsjHzSldedsfz();

            string paramKey = context.Request.Params["id"];
            try
            {
                
                if(string.IsNullOrEmpty(paramKey))
                {
                    mResultModel.ErrorCode = -9991;
                    mResultModel.ISSucceed = false;
                    context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回    
                    return ;
                }
                   mMsjHzSldedsfz = MsjHzSldedsfzBLL.Load(paramKey); //根据键值获取实体信息
                    if (mMsjHzSldedsfz != null)
                    {
                 mMsjHzSldedsfz.Czdsspcs = context.Request.Form["texCzdsspcs"]; //常住地所属派出所(字典)
                 mMsjHzSldedsfz.Xm = context.Request.Form["texXm"]; //姓名
                 mMsjHzSldedsfz.Xb = context.Request.Form["texXb"]; //性别(字典)
                 mMsjHzSldedsfz.Mz = context.Request.Form["texMz"]; //民族(字典)
                 mMsjHzSldedsfz.Sfzh = context.Request.Form["texSfzh"]; //身份证号码
                 mMsjHzSldedsfz.Csrq = context.Request.Form["texCsrq"]; //出生日期
                 mMsjHzSldedsfz.Slrgddh = context.Request.Form["texSlrgddh"]; //申领人固定电话
                 mMsjHzSldedsfz.Czhkdjdz = context.Request.Form["texCzhkdjdz"]; //常住户口登记地址
                 mMsjHzSldedsfz.Ywlb = context.Request.Form["texYwlb"]; //业务类别(数据字典)
                 mMsjHzSldedsfz.Sjjzdz = context.Request.Form["texSjjzdz"]; //实际居住地址
                 mMsjHzSldedsfz.Szdsspcs = context.Request.Form["texSzdsspcs"]; //实住地所属派出所(字典)
                 mMsjHzSldedsfz.Slyy = context.Request.Form["texSlyy"]; //申领原因(1第一次申领 2丢失补领)
                 mMsjHzSldedsfz.Dw = context.Request.Form["texDw"]; //单位
                 if (!string.IsNullOrEmpty(context.Request.Form["H_File"]))
                 {
                     mMsjHzSldedsfz.Zp = new ImageToByte().ToByte("/uploadfiles/" + context.Request.Form["H_File"]);
                 }
                 mMsjHzSldedsfz.Zjydszsheng = context.Request.Form["texZjydszsheng"]; //证件邮递所在省(字典)
                 mMsjHzSldedsfz.Zjydszshi = context.Request.Form["texZjydszshi"]; //证件邮递所在市(字典)
                 mMsjHzSldedsfz.Zjydxxdz = context.Request.Form["texZjydxxdz"]; //证件邮递详细地址
                 mMsjHzSldedsfz.Yb = context.Request.Form["texYb"]; //邮编
                 mMsjHzSldedsfz.Jtcyyxm = context.Request.Form["texJtcyyxm"]; //家庭成员一姓名
                 mMsjHzSldedsfz.Jtcyyyhzgx = context.Request.Form["texJtcyyyhzgx"]; //家庭成员一与户主关系(字典)
                 mMsjHzSldedsfz.Jtcyysfzh = context.Request.Form["texJtcyysfzh"]; //家庭成员一身份证号
                 mMsjHzSldedsfz.Jtcyyczhkdjdz = context.Request.Form["texJtcyyczhkdjdz"]; //家庭成员一常住户口登记地址
                 mMsjHzSldedsfz.Jtcyexm = context.Request.Form["texJtcyexm"]; //家庭成员二姓名
                 mMsjHzSldedsfz.Jtcyeyhzgx = context.Request.Form["texJtcyeyhzgx"]; //家庭成员二与户主关系(字典)
                 mMsjHzSldedsfz.Jtcyesfzh = context.Request.Form["texJtcyesfzh"]; //家庭成员二身份证号
                 mMsjHzSldedsfz.Jtcyeczhkdjdz = context.Request.Form["texJtcyeczhkdjdz"]; //家庭成员二常住户口登记地址
                 mMsjHzSldedsfz.Jtcysxm = context.Request.Form["texJtcysxm"]; //家庭成员三姓名
                 mMsjHzSldedsfz.Jtcysyhzgx = context.Request.Form["texJtcysyhzgx"]; //家庭成员三与户主关系(字典)
                 mMsjHzSldedsfz.Jtcyssfzh = context.Request.Form["texJtcyssfzh"]; //家庭成员三身份证号
                 mMsjHzSldedsfz.Jtcysczhkdjdz = context.Request.Form["texJtcysczhkdjdz"]; //家庭成员三常住户口登记地址
                 mMsjHzSldedsfz.Dbrxm = context.Request.Form["texDbrxm"]; //担保人姓名
                 mMsjHzSldedsfz.Dbrxb = context.Request.Form["texDbrxb"]; //担保人性别(字典)
                 mMsjHzSldedsfz.Dbrmz = context.Request.Form["texDbrmz"]; //担保人民族(字典)
                 mMsjHzSldedsfz.Dbrsfzh = context.Request.Form["texDbrsfzh"]; //担保人身份证号
                 mMsjHzSldedsfz.Dbrlxsj = context.Request.Form["texDbrlxsj"]; //担保人联系手机
                 mMsjHzSldedsfz.Dbrdz = context.Request.Form["texDbrdz"]; //担保人地址
                 mMsjHzSldedsfz.Yzm = context.Request.Form["texYzm"]; //验证码
                 mMsjHzSldedsfz.Cjsj = context.Request.Form["texCjsj"]; //创建时间(2013-05-28 09:13:01)
                 mMsjHzSldedsfz.Cjr = context.Request.Form["texCjr"]; //创建人(人员ID)
                 mMsjHzSldedsfz.Cjrdw = context.Request.Form["texCjrdw"]; //创建单位(单位ID)
                 mMsjHzSldedsfz.Xgr = context.Request.Form["texXgr"]; //修改人(人员ID)
                 mMsjHzSldedsfz.Xgrdw = context.Request.Form["texXgrdw"]; //修改人单位(单位ID)
                 mMsjHzSldedsfz.Xgsj = context.Request.Form["texXgsj"]; //修改时间(2013-05-28 09:13:01)
                 mMsjHzSldedsfz.Enabled = Enabled.TRUE; //是否有效（1有效，0无效）
                 mMsjHzSldedsfz.Movesign = context.Request.Form["texMovesign"]; //是否传输（1已，0未）
            
            mResultModel = MsjHzSldedsfzBLL.Update(mMsjHzSldedsfz,context.Session["UserID"], true); //新建操作
                 }
                else
                 {
                mResultModel.ErrorCode = -9990; //没有获取所需的信息，信息可能已被删除
                mResultModel.ISSucceed = false;               
                 }
                
            context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回
            }
            catch (Exception ex)
            {
                MSEx.DealErr(ex, string.Empty);
                mResultModel.ErrorCode = -9999;
                mResultModel.ISSucceed = false;
                context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回
            }
        }    
        #endregion 
        
        #region 获取实体记录
      /// <summary>
      /// 获取实体记录
      /// </summary>
        protected void GetModel()
        {
            HttpContext context = HttpContext.Current;
            context.Response.ContentType = "text/plain";
             ResultModel mResultModel = new ResultModel(); //初始化返回类型
            string paramKey = context.Request.Params["id"];
            string json = string.Empty;
            try
            {
                MsjHzSldedsfz mMsjHzSldedsfz = new MsjHzSldedsfz(); //声明实体
                if (!string.IsNullOrEmpty(paramKey))
                {
                    mMsjHzSldedsfz = MsjHzSldedsfzBLL.Load(paramKey); //根据键值获取管理员
                    if (mMsjHzSldedsfz != null)
                    {
                        json = JsonConvert.SerializeObject(mMsjHzSldedsfz);
                    }
                }
            }
            catch (Exception ex)
            {
                MSEx.DealErr(ex, string.Empty);
                mResultModel.ErrorCode = -9990;
                mResultModel.ISSucceed = false;
                json = JsonConvert.SerializeObject(mResultModel);
            }
            
            context.Response.Write(json);
        }
        #endregion
      
        #region 获取数据
        /// <summary>
      /// 获取数据记录
      /// </summary>
       protected void QueryRecord()
        {
            TableMessage tm = new TableMessage();
            HearderMessage hm = new HearderMessage();
            List<HearderMessage> list = new List<HearderMessage>();
            HttpContext context = HttpContext.Current;
            context.Response.ContentType = "text/plain";
            string pageSize = context.Request.Form["pageSize"];
            string pageIndex = context.Request.Form["pageIndex"];
            if (String.IsNullOrEmpty(pageSize) || String.IsNullOrEmpty(pageIndex) || !AnyString.IsNumeric(pageSize) || !AnyString.IsNumeric(pageIndex))
            { 
                return;
            }
            
            DataTable dtMsjHzSldedsfz = new DataTable();
            int intPageSize = Convert.ToInt32(pageSize);
            int intPageIndex = Convert.ToInt32(pageIndex);
            QueryByPage q=new QueryByPage();
            QueryInfo qInfo=new QueryInfo();
            dtMsjHzSldedsfz = q.GetRecordByPage("*", string.Empty, string.Empty, intPageSize, intPageIndex,  MsjHzSldedsfzConst.TableName, MsjHzSldedsfzConst.FieldKey, string.Empty).Tables[0];
            if (dtMsjHzSldedsfz != null && dtMsjHzSldedsfz.Rows.Count > 0)
             {
                 for (int i = 0; i < dtMsjHzSldedsfz.Columns.Count; i++)
                 {
                     hm = new HearderMessage();
                     hm.name = dtMsjHzSldedsfz.Columns[i].Caption;
                     list.Add(hm);
                 }
                
                 tm.Header = list;
                 tm.data = dtMsjHzSldedsfz;
                 tm.totalCount = Convert.ToString((int)q.RowCount);
             }
            
            string json = JsonConvert.SerializeObject(tm);
            context.Response.Write(json);
        }
       
       protected void QueryGtRecord()
        {
           HttpContext context = HttpContext.Current;
           context.Response.ContentType = "text/plain";

           QueryInfo info = new QueryInfo();
           QueryByPage page = new QueryByPage();
           info.FieldKey = MsjHzSldedsfzConst.FieldKey;
           info.PageIndex = 1;
           info.PageSize = 0;
           info.QTableName = MsjHzSldedsfzConst.TableName;
           info.SelectFields = "*";

           info.Where = string.Empty;
           DataSet ds = page.GetRecordByPage(info);
           DataTable table = new DataTable();
        
           if (ds.Tables.Count > 0)
           {
               table = page.GetRecordByPage(info).Tables[0];
           }
           string json = JsonConvert.SerializeObject(table);
           context.Response.Write(json);
        }
         #endregion           
}
}
 
 
